import { HttpService } from '@/shared/api/httpService';
import type { User, CreateUserRequest } from './domain';
import {AppBackendService} from "@/shared/api/appBackendService";

class UsersService extends AppBackendService {


    private urls = {
        users: '/users',
    };

    getUsers = async (): Promise<User[]> => {
        const result = await this.request<User[]>(this.urls.users, {}, { method: 'GET' });

        return result;
    };

    getUserById = async (id: number): Promise<User | undefined> => {
        const users = await this.request<User[]>(this.urls.users, { queryParams: { id } }, { method: 'GET' });
        return users[0];
    };

    createUser = async (data: CreateUserRequest): Promise<User> => {
        const result = await this.request<User>(this.urls.users, { body: data }, { method: 'POST' });

        return result;
    };
}

export const usersService = new UsersService();
// Also export the class and instance for backward compatibility
export { UsersService };
